﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;

namespace LambdaToSql.EntityModel
{
    /// <summary>
    /// 基础实体类
    /// </summary>
    internal class BaseEntity<T> where T : class, new()
    {
        #region 属性

        /// <summary>
        /// 数据库上下文对象
        /// </summary>
        internal LambdaToSql.EntityModel.DbContext Context { get; set; }

        /// <summary>
        /// 表名
        /// </summary>
        [DataMember]
        public virtual string TableName { get; set; }

        /// <summary>
        /// 类型T Type
        /// </summary>
        [DataMember]
        public virtual Type TType { get; set; }

        /// <summary>
        /// 返回当前 T 的所有公共属性。
        /// </summary>
        [DataMember]
        public virtual PropertyInfo[] Properties { get; set; } 
        #endregion

        /// <summary>
        /// 初始化默认参数
        /// </summary>
        /// <param name="context"></param>
        public BaseEntity(DbContext context)
        {
            this.Context = context;

            this.TType = typeof(T);
            this.Properties = this.TType.GetProperties();
            this.TableName = this.TType.Name;
        }
    }
}
